package vm.project;

import java.io.FileOutputStream;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;


public class GestionKML {
    static Element racine = new Element("kml");
    static Document document = new Document(racine);
    
    public void groundOverlay(String nom,String desc,String image,double boundScale,double dnorth,double dsouth,double deast, double dwest){
      Element ground = new Element("GroundOverlay");

      Element name = new Element("name");
      name.setText(nom);
      ground.addContent(name);

      Element description = new Element("description");
      description.setText(desc);
      ground.addContent(description);

      Element icon = new Element("Icon");
        Element href = new Element("href");
        href.setText(image);
        icon.addContent(href);
        
        Element viewBoundScale = new Element("viewBoundScale");
        viewBoundScale.setText(Double.toString(boundScale));
        icon.addContent(viewBoundScale);
      ground.addContent(icon);

      Element latLonBox = new Element("LatLonBox");
      
        Element north = new Element("north");
        north.setText(Double.toString(dnorth));
        latLonBox.addContent(north);
        
        Element south = new Element("south");
        south.setText(Double.toString(dsouth));
        latLonBox.addContent(south);
        
        Element east = new Element("east");
        east.setText(Double.toString(deast));
        latLonBox.addContent(east);
        
        Element west= new Element("west");
        west.setText(Double.toString(dwest));
        latLonBox.addContent(west);
        
      ground.addContent(latLonBox);
      
      racine.addContent(ground);
      
    }
    
    public void enregistrer(String fichier){
           try{
               //On utilise ici un affichage classique avec getPrettyFormat()
               XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
               //Remarquez qu'il suffit simplement de créer une instance de FileOutputStream
               //avec en argument le nom du fichier pour effectuer la sérialisation.
               sortie.output(document, new FileOutputStream(fichier));
            }
            catch (java.io.IOException e){e.printStackTrace();}
    }
}
